<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Type;
use app\models\Product;

/* @var $this yii\web\View */
/* @var $searchModel app\models\ProductSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title ='产品';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="product-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('创建产品', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'pid',
            [
                'attribute' => 'type_id',
                'value'=>function($model){
                    /* @var $model app\models\Product */
                    return Type::dropdown('type',$model->type_id);
                },
                'filter'=>Type::dropdown('type'),
                'filterInputOptions'=>['prompt'=>'全部','class'=>'form-control'],
                'headerOptions'=>['width'=>'10%'],
            ],
            'name',
//            'hot',
//            'market_val',
            // 'cost',
            // 'return_rate',
            // 'start_price',
            // 'scope',
            // 'fee',
            // 'auction',
            // 'lowest_price',
            // 'highest_price',
            // 'actcount',
            // 'reacount',
            // 'can_robot',
            // 'have_cost',
            // 'ios',
            // 'can_give',
            // 'kind',
            // 'can_show',
            [
                'attribute' => 'state',
                'value'=>function($model){
                    /* @var $model app\models\Product */
                    return Product::dropdown('state',$model->state);
                },
                'filter'=>Product::dropdown('state'),
                'filterInputOptions'=>['prompt'=>'全部','class'=>'form-control'],
                'headerOptions'=>['width'=>'10%'],
            ],
            [
                'attribute' => 'created_at',
                'format' => ['date', 'php:Y-m-d']
            ],
            [
                'attribute' => 'updated_at',
                'format' => ['date', 'php:Y-m-d']
            ],

            [
                'class' => 'yii\grid\ActionColumn',
                'template'=>'{view}{update}{delete}{ready}',
                'buttons'=>[
                    'ready' => function ($url, $model, $key) {
                        return Html::a('&nbsp;<span class="glyphicon glyphicon-bishop"></span>',
                            ['auction/ready','product_id'=>$model->pid],
                            ['title' => '参与竞拍'] );
                    },
                ]
            ],
        ],
    ]); ?>
</div>
